//
//  HEMapAddressInfoCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/12.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMapAddressInfoCell.h"

@interface HEMapAddressInfoCell ()

@property(nonatomic, strong) UILabel *titleLb;
@property(nonatomic, strong) UILabel *distanceLb;
@property(nonatomic, strong) UILabel *addressLb;

@end

@implementation HEMapAddressInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
  
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _titleLb = [UILabel new];
    _titleLb.font = DYFont(16);
    _titleLb.text = @"-";
    _titleLb.textColor = CNavLightBlackColor;
    [self.contentView addSubview:_titleLb];
    
    _distanceLb = [UILabel new];
    _distanceLb.font = DYFont(15);
    _distanceLb.text = @"0m";
    _distanceLb.textColor = CNavSubTitleColor;
    [self.contentView addSubview:_distanceLb];
    
    _addressLb = [UILabel new];
    _addressLb.font = DYFont(15);
    _addressLb.text = @"-";
    _addressLb.textColor = CNavSubTitleColor;
    _addressLb.numberOfLines = 0;
    [self.contentView addSubview:_addressLb];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [_titleLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    
    [_distanceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_titleLb.mas_left);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
    [_distanceLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    UIView *line = [UIView new];
    line.backgroundColor = CSplitLineColor;
    [self.contentView addSubview:line];

    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_distanceLb.mas_right).mas_offset(10);
        make.width.mas_offset(1);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];

    [_addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.left.equalTo(line.mas_right).mas_offset(10);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-15);
        make.bottom.equalTo(self.contentView.mas_bottom).mas_offset(-10);
    }];
}

- (void)setModel:(HEReceiveAddressModel *)model {
    _titleLb.text = model.addressTitle;
    _addressLb.text = model.KCRString;
    _distanceLb.text = model.distance;
    
    if (model.isSelect) {
        self.accessoryType = UITableViewCellAccessoryCheckmark;
    }else {
        self.accessoryType = UITableViewCellAccessoryNone;
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
